/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package autowus.gui.module;

import auto.wus.Sprawdzanie;
import auto.wus.SprawdzanieDzisiejsze;
import autowus.gui.appointment.AppointmentFrame;
import autowus.gui.options.OptionsFrame;
import autowus.gui.single.SingleFrame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import java.util.Calendar;
import java.util.TimeZone;


import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;

/**
 *
 * @author Quark
 */
public class MainPanel extends javax.swing.JPanel {
    
    DaysAppointmentsPanel daysAppointmentsPanel;
    DaysReservationsPanel daysReservationsPanel;

    /**
     * Creates new form MainPanel
     * @throws SchedulerException 
     * @throws ParseException 
     */
    public MainPanel() throws SchedulerException, ParseException {
        initComponents();
        initCustom();
        
        Scheduler scheduler =  new StdSchedulerFactory().getScheduler();
        JobDetail jobDetail = new JobDetail("przykład", null,
                        Sprawdzanie.class);
    Trigger trigger = new CronTrigger("simple", null, "00 00 16 ? * *");
        scheduler.scheduleJob(jobDetail, trigger);     
        scheduler.start();
        
        
        
        Scheduler scheduler1 =  new StdSchedulerFactory().getScheduler();
        JobDetail jobDetail1 = new JobDetail("przykład1", null,
                        SprawdzanieDzisiejsze.class);
    Trigger trigger1 = new CronTrigger("simple1", null, "00 00 08 ? * *");
        scheduler1.scheduleJob(jobDetail1, trigger1);     
        scheduler1.start();
        
        Calendar calendar = Calendar.getInstance();
        if(calendar.get(Calendar.HOUR_OF_DAY)>8){
        SprawdzanieDzisiejsze sprawdz =  new SprawdzanieDzisiejsze();
        sprawdz.execute(null);
        }
        
        optionsBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evnt) {
                OptionsFrame optionsFrame = new OptionsFrame();
                optionsFrame.setVisible(true);
                System.out.println("optionsBtn clicked. Additional frame opened.");
            }
        });
        
        checkOneBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evnt) {
                SingleFrame singleFrame = new SingleFrame();
                singleFrame.setVisible(true);
                System.out.println("checkOneBtn clicked. Additional frame opened.");
            }
        });
        
        addAppBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evnt) {
                AppointmentFrame appointmentFrame = new AppointmentFrame();
                appointmentFrame.setVisible(true);
                System.out.println("addAppBtn clicked. Additional frame opened.");
            }
        });
    }
    
    private void initCustom() {
        daysAppointmentsPanel = new DaysAppointmentsPanel();
        daysReservationsPanel = new DaysReservationsPanel();
        
        // default font
        //tabbedPanel.addTab("<html><body leftmargin = 182 topmargin = 8 marginwidth = 182 marginheight = 5>Wizyty dnia</body></html>", daysAppointmentsPanel);
        //tabbedPanel.addTab("<html><body leftmargin = 182 topmargin = 8 marginwidth = 182 marginheight = 5>Rezerwacje dnia</body></html>", daysAppointmentsPanel2);
        
        // Ubuntu 13 pt font
        tabbedPanel.addTab("<html><body leftmargin = 174 topmargin = 8 marginwidth = 174 marginheight = 5>Wizyty dnia</body></html>", daysAppointmentsPanel);
        tabbedPanel.addTab("<html><body leftmargin = 175 topmargin = 8 marginwidth = 175 marginheight = 5>Rezerwacje dnia</body></html>", daysReservationsPanel);
    tabbedPanel.addChangeListener(new ChangeListener() {

            public void stateChanged(ChangeEvent e) {
                System.out.print("odswiezono");
             daysAppointmentsPanel.odswiez();
             daysAppointmentsPanel.repaint();
            //daysReservationsPanel.odswiez();
            }
        });
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        logoIconLabel = new javax.swing.JLabel();
        tabbedPanel = new javax.swing.JTabbedPane();
        copyrightLabel = new javax.swing.JLabel();
        addAppBtn = new javax.swing.JButton();
        checkOneBtn = new javax.swing.JButton();
        optionsBtn = new javax.swing.JButton();

        setBackground(new java.awt.Color(2, 148, 75));
        setMaximumSize(new java.awt.Dimension(890, 530));
        setMinimumSize(new java.awt.Dimension(890, 530));
        setPreferredSize(new java.awt.Dimension(890, 530));

        logoIconLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/autowus/gui/graphics/module/main/autoWUŚ_main_logo.png"))); // NOI18N
        logoIconLabel.setText("jLabel1");
        logoIconLabel.setMaximumSize(new java.awt.Dimension(135, 75));
        logoIconLabel.setMinimumSize(new java.awt.Dimension(135, 75));
        logoIconLabel.setPreferredSize(new java.awt.Dimension(135, 75));

        tabbedPanel.setMaximumSize(new java.awt.Dimension(890, 365));
        tabbedPanel.setMinimumSize(new java.awt.Dimension(890, 365));
        tabbedPanel.setPreferredSize(new java.awt.Dimension(890, 365));

        copyrightLabel.setForeground(new java.awt.Color(255, 255, 255));
        copyrightLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        copyrightLabel.setText("All rights reserved ® & Copyright © 2013 by Completely Unprepared");
        copyrightLabel.setMaximumSize(new java.awt.Dimension(34, 20));
        copyrightLabel.setMinimumSize(new java.awt.Dimension(34, 20));
        copyrightLabel.setPreferredSize(new java.awt.Dimension(34, 20));

        addAppBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/autowus/gui/graphics/module/main/autoWUŚ_main_add_app.png"))); // NOI18N
        addAppBtn.setText(" ");
        addAppBtn.setToolTipText("Dodaj wizytę do kalendarza.");
        addAppBtn.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        addAppBtn.setBorderPainted(false);
        addAppBtn.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/autowus/gui/graphics/module/main/autoWUŚ_main_add_app_in.png"))); // NOI18N
        addAppBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        addAppBtn.setMaximumSize(new java.awt.Dimension(161, 58));
        addAppBtn.setMinimumSize(new java.awt.Dimension(161, 58));
        addAppBtn.setOpaque(false);
        addAppBtn.setPreferredSize(new java.awt.Dimension(161, 58));
        addAppBtn.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/autowus/gui/graphics/module/main/autoWUŚ_main_add_app_clicked.png"))); // NOI18N

        checkOneBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/autowus/gui/graphics/module/main/autoWUŚ_main_check_one.png"))); // NOI18N
        checkOneBtn.setText(" ");
        checkOneBtn.setToolTipText("Zweryfikuj pojedynczego pacjenta w drodze wyjątku.");
        checkOneBtn.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        checkOneBtn.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/autowus/gui/graphics/module/main/autoWUŚ_main_check_one_in.png"))); // NOI18N
        checkOneBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        checkOneBtn.setMaximumSize(new java.awt.Dimension(161, 58));
        checkOneBtn.setMinimumSize(new java.awt.Dimension(161, 58));
        checkOneBtn.setOpaque(false);
        checkOneBtn.setPreferredSize(new java.awt.Dimension(161, 58));
        checkOneBtn.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/autowus/gui/graphics/module/main/autoWUŚ_main_check_one_clicked.png"))); // NOI18N

        optionsBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/autowus/gui/graphics/module/main/autoWUŚ_main_options.png"))); // NOI18N
        optionsBtn.setToolTipText("Otwórz okno dodatkowych opcji.");
        optionsBtn.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        optionsBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        optionsBtn.setMaximumSize(new java.awt.Dimension(161, 58));
        optionsBtn.setMinimumSize(new java.awt.Dimension(161, 58));
        optionsBtn.setOpaque(false);
        optionsBtn.setPreferredSize(new java.awt.Dimension(161, 58));
        optionsBtn.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/autowus/gui/graphics/module/main/autoWUŚ_main_options_clicked.png"))); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(logoIconLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(optionsBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(checkOneBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(addAppBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(tabbedPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(copyrightLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 455, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(logoIconLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(addAppBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(checkOneBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(optionsBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(tabbedPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 365, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(copyrightLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 43, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addAppBtn;
    private javax.swing.JButton checkOneBtn;
    private javax.swing.JLabel copyrightLabel;
    private javax.swing.JLabel logoIconLabel;
    private javax.swing.JButton optionsBtn;
    private javax.swing.JTabbedPane tabbedPanel;
    // End of variables declaration//GEN-END:variables
}
